package com.zxj.camerapreview;

import androidx.appcompat.app.AppCompatActivity;

import android.hardware.Camera;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;

public class CameraHelperActivity extends AppCompatActivity implements Camera.PreviewCallback, CameraHelper.OnChangedSizeListener {

    private CameraHelper mCameraHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera_helper);
        SurfaceView mSurfaceView = findViewById(R.id.surfaceView);
        mCameraHelper = new CameraHelper(this, 0, 1920, 1080);
        mCameraHelper.setPreviewDisplay(mSurfaceView.getHolder());
        mCameraHelper.setPreviewCallback(this);
        mCameraHelper.setOnChangedSizeListener(this);
    }

    public void onSwitchClick(View view){
        mCameraHelper.switchCamera();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onPreviewFrame(byte[] bytes, Camera camera) {
//        Log.e("CameraHelper","bytes:"+bytes+",camera:"+camera);
    }

    @Override
    public void onChanged(int w, int h) {
        Log.e("CameraHelper","width:"+w+",height:"+h);
    }
}